import random

from core.models import Rating, Restaurant, Sale, Staff, StaffRestaurant
from django.contrib.auth.models import User
from django.utils import timezone
from django.db.models import Avg, Value, CharField, Sum, Count, F, Q
from django.db.models.functions import Lower, Concat


def run():
    it_or_mex = Q(name__icontains='italian') | Q(name__icontains='mexican')
    not_recently_opened = ~Q(date_opened__gt=timezone.now() - timezone.timedelta(days=40))

    restaurants = Restaurant.objects.filter(it_or_mex | not_recently_opened)
    print(restaurants)

    name_has_num = Q(restaurant__name__regex=r'[0-9]+')
    profited = Q(income__gt=F('expenditure'))
    sales = Sale.objects.filter(name_has_num,  profited).values(restaurant_name=F('restaurant__name'))
    print(sales)

